public class test1 {
    //力扣 704 二分查找
    public int search(int[] nums, int target) {
        int left = 0;
        int right = nums.length -1;
        int mid = 0;
        while(left<=right){
            //left+right 容易使数据溢出
//            mid = (left+right)/2;
            //防溢出
            mid = left + (right-left)/2;
            if(target>nums[mid]){
                left = mid+1;
            }else if(target<nums[mid]){
                right = mid-1;
            }else{
                return mid;
            }
        }
        return -1;
    }
}
